/*========= Starting function =========*/
$(document).ready(function() {
    $('.antiscroll-wrap').antiscroll();
});


function showAlert(msg) {
	if(!msg) 
		return false;

	var modal = $('#pageAlertModal');
	if(modal.length == 0) {
		var html = '<div id="pageAlertModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">\
					<div class="modal-header">\
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\
						<h3 id="myModalLabel">Alert</h3>\
					</div>\
					<div class="modal-body"></div>\
					<div class="modal-footer">\
						<a class="button sButton bMuddy" href="#" data-dismiss="modal" aria-hidden="true">Close</a>\
					</div>\
				</div>';
		$('body').append(html);
	}
	$('#pageAlertModal').find('.modal-body').html('<p>' + msg + '</p>');
	$('#pageAlertModal').modal();
	return false;
}

function showConfirm(options) {
	var title = options.title ? options.title : 'Please Confirm Your Action.',
		msg = options.msg ? options.msg : '',
		noBt = options.noBt ? options.noBt : 'No',
		yesBt = options.yesBt ? options.yesBt : 'Yes',
		warning = options.warning ? '<p class="text-warning" align="left">' + options.warning + '</p>' : '',
		onYes = options.onYes ? options.onYes : null,
		onNo = options.onNo ? options.onNo : null,
		param = options.param ? options.param : null;
		
	var modal = $('#pageConfirmModal');
	if(modal.length == 0) {
		var html = '<div id="pageConfirmModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="confirmLable" aria-hidden="true">\
						<div class="modal-header">\
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\
							<h3 id="confirmLable">' + title + '</h3>\
						</div>\
						<div class="modal-body">' + msg + '</div>\
						<div class="modal-footer">\
							' + warning + '\
							<a class="button sButton bAtina" href="#" data-dismiss="modal" aria-hidden="true">' + noBt + '</a>\
							<a id="confirmOnYes" class="button sButton bMuddy deleteUser" data-dismiss="modal" aria-hidden="true" href="#">' + yesBt + '</a>\
						</div>\
					</div>';
		$('body').append(html);
	}
	$('#pageConfirmModal').modal('show');
	$('#pageConfirmModal #confirmOnYes').click(function() {
		$.isFunction(onYes) && onYes(param);
	});
	$('#pageConfirmModal').on('hidden', function () {
		$.isFunction(onNo) && onNo(param);
		$('#pageConfirmModal').remove();
    });
}

Array.prototype.getUnique = function(){
   var u = {}, a = [];
   for(var i = 0, l = this.length; i < l; ++i){
      if(u.hasOwnProperty(this[i])) {
         continue;
      }
      a.push(this[i]);
      u[this[i]] = 1;
   }
   return a;
}